package com.hook3.pianke.Adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.hook3.pianke.R;
import com.hook3.pianke.activity.ReadingActivity;

import org.w3c.dom.Text;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2015/12/9.
 */
public class ReadVGridViewAdapter extends BaseAdapter {
    private Activity activity;
    private List<ReadingActivity.MainImageGridVIew> gridImageUrl;

    public ReadVGridViewAdapter(Activity activity, List<ReadingActivity.MainImageGridVIew> gridImageUrl) {
        this.activity = activity;
        this.gridImageUrl = gridImageUrl;
    }


    @Override
    public int getCount() {
        return gridImageUrl.size();
    }

    @Override
    public Object getItem(int position) {
        return gridImageUrl.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    ViewHolder viewHolder;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = View.inflate(activity, R.layout.item_read_gridview,null);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.iv_item_read);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.tv_item_read);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ReadingActivity.MainImageGridVIew mainImageGridVIew = gridImageUrl.get(position);
        x.image().bind(viewHolder.imageView,mainImageGridVIew.coverimg);
        viewHolder.textView.setText(mainImageGridVIew.name);
        return convertView;
    }
    static class ViewHolder {
        public ImageView imageView;
        public TextView textView;
    }
}
